package cn.fufeiii.bt.common.config;

import com.alibaba.ttl.TtlRunnable;
import org.springframework.boot.task.TaskExecutorCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ThreadPoolExecutor;

/**
 * 默认的spring执行线程池配置
 *
 * @author FuFei
 */
@Configuration
public class ExecutionPoolConfig {

    @Bean
    public TaskExecutorCustomizer taskExecutorCustomizer() {
        return taskExecutor -> {
            taskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
            taskExecutor.setTaskDecorator(TtlRunnable::get);
        };
    }

}
